import java.util.Scanner;

/**
 * @author gao
 * @date 2025/7/2 10:58
 */

class ListNode {
    int val;
    ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

public class Solution {
    public ListNode swapPairs(ListNode head) {
        // 如果链表为空或只有一个节点，则直接返回
        if (head == null || head.next == null) {
            return head;
        }

        ListNode newHead = new ListNode(0,head);

        ListNode prev = newHead, cur = prev.next, nextO = cur.next, nextON = nextO.next;

        // 遍历链表，每次交换cur和nextO的位置
        while (cur != null && nextO != null) {
            prev.next = nextO;
            nextO.next = cur;
            cur.next = nextON;

            prev = cur;
            cur = nextON;
            // 如果cur不为空，则将nextO指向cur的下一个节点
            if (cur != null) {
                nextO = cur.next;
            }
            // 如果nextO不为空，则将nextON指向nextO的下一个节点
            if (nextO != null) {
                nextON = nextO.next;
            }
        }
        // 返回新链表的头节点
        return newHead.next;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            ListNode head = null;
            ListNode tail = null;
            int n = in.nextInt();

            for (int i = 0; i < n; i++) {
                int val = in.nextInt();
                ListNode newNode = new ListNode(val);
                if (head == null) {
                    head = newNode;
                    tail = newNode;
                } else {
                    tail.next = newNode;
                    tail = newNode;
                }
            }
            Solution solution = new Solution();
            Print(solution.swapPairs(head));
        }
    }

    private static void Print(ListNode head) {
        ListNode cur = head;
        while (cur != null) {
            System.out.print(cur.val + " ");
            cur = cur.next;
        }
    }
}